<?php
namespace app\common\model;
use \think\Model;
use \think\Db;
use JPush\Client;
use \think\Request;
use \think\Loader;
use think\Session;

use think\Cache;

class JPush extends Model
{
    private $appKey = 'ed61a661ab87ed847310f99d';
    private $masterSecret = '1b804dcfad3344f98bbb1863';
    
    public function sends($title, $summary,$id,$type,$url){
            
        $client = new Client($this->appKey, $this->masterSecret);
        
        $pusher = $client->push();
        $pusher->setPlatform('all');
        $pusher->addAllAudience();
        //$pusher->setNotificationAlert($title);
        $pusher->iosNotification($title, [
          'sound' => 'sound',
          'badge' => '+1',
          'extras' => [
            'title' => $title,
            'summary' => $summary,
            'id' => $id,
            'type' => $type,
            'url'=>$url
            
          ]
        ]);
        $pusher->androidNotification($title, [
          'title' => $title,
          //'content_type' => 'text',
          'extras' => [
            'title' => $title,
            'summary' => $summary,
            'id' => $id,
            'type' => $type,
            'url'=>$url
          ]
        ]);
        $options = array(
            //'apns_production'=>true
        );
        $pusher->options($options);
        //var_dump($res);die;
        try {
            $res = $pusher->send();
            return $res;
            //var_dump($res);
        } catch (\JPush\Exceptions\JPushException $e) {
            // try something else here
            print $e;
        }
    }

}